<!-- Imports -->
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Hashtable"%>
<%@page import="canss.supports.basic"%>
<%@page import="canss.supports.Makequery_select"%>
<!-- Component start -->
<%
	{
%>
<!-- Initiation -->
<%
	response.setContentType("text/html; charset=UTF-8");
		canss.web.controls.WebDBControl webdbcontrol = null;
		webdbcontrol = (webdbcontrol == null) ? new canss.web.controls.WebDBControlBean() : webdbcontrol;
%>
<!-- Preparing inputs -->
<%
	int i = 0;
%>
<!-- Query Compilation -->
<%
	Makequery_select query = new Makequery_select().Select("COUNT(tblMID_mid) as count, midstatus").PushFrom("tblModuleDescription").GroupBy("midstatus").PushWhere("name like \"%agg%\"");

		Iterator<String[]> iter = null;
		Hashtable<String, Integer> hash = null;
		try
		{
			LinkedList<String[]> res = webdbcontrol.Select(query);
			iter = res.iterator();
			if (iter.hasNext())
			{
				String[] curhashtmp = iter.next();
				hash = new Hashtable<String, Integer>(curhashtmp.length);
				for (i = 0; i < curhashtmp.length; i++)
					hash.put(curhashtmp[i], i);
			}
		} catch (Exception e)
		{
			e.printStackTrace();
		}
%>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
		// Load the Visualization API and the piechart package.
		google.load('visualization', '1', {'packages':['piechart']});
		// Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChartAggregator_div);
    function drawChartAggregator_div()
    {
			var aggdata = new google.visualization.DataTable();
			aggdata.addColumn('string', 'Status');
			aggdata.addColumn('number', 'Counts');
			<%
				out.write("aggdata.addRows([");
				boolean isfirstiter = true;
				while(iter!=null && iter.hasNext())
				{
					String[] cur = iter.next();
					if(isfirstiter)
					{
						isfirstiter = false;
					}else
						out.write(",\n");
					out.write(String.format(" ['%s', %s]", cur[hash.get("midstatus")], cur[hash.get("count")]));
				}
				out.write("]);");
			%>
			var aggchart = new google.visualization.PieChart(document.getElementById('Aggregator_div'));
			aggchart.draw(aggdata, {width: 300, height: 240, is3D: true, title: 'Aggregator Infomation'});
		}
	</script>

<div id="Aggregator_div"></div>
<%
	}
%>
<!-- Component end -->